<?php
/**
 * Classe Sponsorship
 *
 * Description de la classe:parrainage
 *
 * @author Valentin
 */

class Sponsorship extends Object {
    protected $id;
    protected $type;
    protected $sponsor;

    function __construct($id="", $params=array()) {
        if($id!='') {
            $this->id = $id;
            foreach($params as $key => $p) {
                $this->$key = $p;
            }
        }
    }

    public function addChild($user) {
        if(isset($this->sponsor)) {
            $db = Database::getInstance();
            $sql = "INSERT INTO parrainage VALUES('', '".$this->sponsor['id']."', '".$user['id']."', '".$this->type."')";
            $db->query($sql);
            $this->sponsor->addChild($user, $this->type);
        }
    }

    static public function exist($user, $hash){
        if($user['hash'] == $hash) return true;
        return false;

    }

}
?>